﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate.Tool.hbm2ddl;
using NHCfg = NHibernate.Cfg;

namespace InnovTech.Persistence.NHibernate.Test
{
    public class TestBuilder : SessionFactoryBuilderBase<TestDababaseInfo>
    {

        public TestBuilder(TestDababaseInfo info)
            : base(info)
        {
        }


        protected override global::NHibernate.Cfg.Configuration GetConfiguration(TestDababaseInfo dbInfo)
        {
            NHCfg.Configuration config = new NHCfg.Configuration();
            config.AddProperties(dbInfo.GetConfigurationProperties());
            config.Properties.Add(NHCfg.Environment.ConnectionString, dbInfo.GetConnectionString());
            dbInfo.GetMappingAction<NHCfg.Configuration>()(config);
            return config;
        }

        public void ExportTestSchema()
        {
            var config = BuildConfiguration();
            SchemaExport exporter = new SchemaExport(config);
            exporter.Create(false, true);

        }
    }

    public class TestBulderWithFailure : TestBuilder
    {
        public TestBulderWithFailure(TestDababaseInfo info)
            : base(info)
        {
        }

        protected override NHCfg.Configuration GetConfiguration(TestDababaseInfo dbInfo)
        {
            return null;
        }
    }

}
